//
//  SendViewController.swift
//  Swift_SendMessage
//
//  Created by lanou3g on 15/11/25.
//  Copyright © 2015年 笨蛋一号后卫. All rights reserved.
//

import UIKit

class SendViewController: UIViewController {
//typealias 和OC中的typedef一样
    //格式 ：名字 = （参数） -> 返回值
    typealias closure =  () -> Void
    //定义属性
    var result : closure!
    @IBOutlet weak var textView: UITextView!
    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
 
    @IBAction func sendButtonClicked(sender: AnyObject) {
        let object = PFObject(className: "yan30Message")
        object.setObject(self.textView.text, forKey: "message")
        let (userName, userId) = UserManaged.defaultManager().findUserSince()
        
        object.setObject(userName, forKey: "userName")
        object.setObject(userId, forKey: "UID")
        object.saveInBackgroundWithBlock { (succeed, error) -> Void in
            if succeed {
                self.result()
                self.navigationController?.popToRootViewControllerAnimated(true)
                
            }
        }
        
        
    }
    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
